﻿@using SageKing.Database.EF.Contracts
@rendermode InteractiveServer

@namespace SageKing.Blazor.OpenIdService.Components.Base

@code
{
	//用于存放共用RenderFragment

	public RenderFragment GetDetails(EntityBase<string> context)
	{
		if (context == null)
		{
			return @<div style="min-width:266px;"></div>;
		}
		return
	@<div style="min-width:266px;">
			<GridRow Gutter="24">
				<GridCol Span="12"><Text Ellipsis="true">创建时间:</Text></GridCol>
				<GridCol Span="12"><Text>创建人:</Text></GridCol>
			</GridRow>
			<GridRow Gutter="24">
				<GridCol Span="12"><Text Ellipsis="true">@context.CreateTime</Text></GridCol>
				<GridCol Span="12"><Text>@context.CreateUserName</Text></GridCol>
			</GridRow>
			<GridRow Gutter="24">
				<GridCol Span="12"><Text>更新时间:</Text></GridCol>
				<GridCol Span="12"><Text>更新人:</Text></GridCol>
			</GridRow>
			<GridRow Gutter="24">
				<GridCol Span="12"><Text>@context.UpdateTime</Text></GridCol>
				<GridCol Span="12"><Text>@context.UpdateUserName</Text></GridCol>
			</GridRow>
		</div>;
	}


	public RenderFragment<PaginationTotalContext> showTotal = ctx => @<div class="showTotal">Total: <b>@ctx.Total</b></div>;

	public RenderFragment ShowHeader(string filedName) => @<div class="showTotal">Header: <b>@filedName</b></div>;

	/// <summary>
	/// 时间相关
	/// </summary>
	/// <param name="render"></param>
	/// <param name="title"></param>
	/// <returns></returns>
	public RenderFragment GetPopoverCellRender(RenderFragment render, string title = "时间相关")
	{
		return
		@<Popover ContentTemplate=@render Title=@title>
			<Button Icon="@IconType.Outline.OrderedList" Shape="@ButtonShape.Circle" />
		</Popover>
		;
	}

	public RenderFragment GetModal<T>(IModal<T> modal)
	where T : ICloneable
	{
		var onOkAction = EventCallback.Factory.Create<MouseEventArgs>(this, modal.HandleOk);
		var HandleCloseAction = EventCallback.Factory.Create<MouseEventArgs>(this, modal.HandleClose);

		return
		@<Modal Title="@modal.Title" Class="@modal.Class" MaxBodyHeight="@modal.MaxBodyHeight" Resizable=true Width="@modal.Width"
		@bind-Visible="@modal.Visible" Draggable="@modal.Draggable" Centered=@modal.Centered Closable=@modal.Closable
						OnOk="onOkAction" OnCancel="HandleCloseAction"
						ConfirmLoading="modal.Loading" OkText="modal.OkTitle" CancelText="modal.CancelText">

		@modal.ModalTemplate
		</Modal>
		;
	}

	public virtual RenderFragment GetTextCellRender<TT>(CellData<TT> cellData, string filedName,string fromatValue)
	{
		return @<Text>@fromatValue</Text>; }
	}

}
